#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
//http://www.oj7.cn/
int n, sum, manxn = -INT16_MAX, a[100001];


int main()
{
	///*cout << manxn<< endl;*/-32767
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	/*5
		1 2 - 5 11 3*/
	sum = 0;
	for (int i = 1; i <= n; i++)
	{

		sum += a[i];
		if (sum > manxn)
		{
			manxn = sum;
		}
		if (sum < 0)
		{
			sum = 0;
		}
	}
	cout << manxn << endl;
	return 0;

}